<ul class="nav nav-pills">
    <?php foreach ($this->container as $page) { ?>
        <?php // when using partials we need to manually check for ACL conditions ?>
        <?php
        if (!$page->isVisible() || !$this->navigation()->accept($page)) {
            continue;
        }
        ?>
    <?php $hasChildren = $page->hasPages(); ?>
                <?php if (!$hasChildren) { ?>
            <li <?php if ($page->isActive()) {
                        echo 'class="active"';
                    } ?> >
                <a href="<?php echo $page->getHref() ?>">
            <?php echo $this->translate($page->getLabel()) ?>
                </a>
            </li>
        <?php
        } else {
            //mark parent active if one of its children is actively

            $flag = 0;
            foreach ($page->getPages() as $child) {
                if (!$child->isVisible() || !$this->navigation()->accept($child)) {
                    continue;
                }
                if ($child->isActive()) {
                    $flag = 1;
                }
            }
            ?>
            <li class="dropdown <?php if($flag)  echo ' active';?>">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo $this->translate($page->getLabel()) ?> <b class="caret"></b></a>
                <ul class="dropdown-menu">
                            <?php foreach ($page->getPages() as $child) { ?>
                                <?php // when using partials we need to manually check for ACL conditions  ?>
            <?php
            if (!$child->isVisible() || !$this->navigation()->accept($child)) {
                continue;
            }
            ?>
                        <li>
                            <a href="<?php echo $child->getHref() ?>">
            <?php echo $this->translate($child->getLabel()) ?>
                            </a>
                        </li>
        <?php } ?>
                </ul>
            </li>
    <?php } ?>
<?php } ?>

